package com.pojoin.cms.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;
import com.pojoin.cms.session.SessionServer;
import com.pojoin.cms.session.SessionServerLocal;
import com.pojoin.cms.verification.Verification;

public class BaseActionSupport extends ActionSupport  implements  ServletRequestAware, ServletResponseAware {

	private static final long serialVersionUID = 1L;

	/**
	 * session 容器
	 */
	private HttpSession httpSession;
	
	/**
	 * session容器
	 */
	protected SessionServer sessionServer;
	
	/**
	 * 验证类
	 */
	protected Verification verification;
	
	protected String target;
	protected HttpServletResponse response;   
	protected HttpServletRequest request;
	protected String msg;
	private String requestURL;
	
	
	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public HttpSession getHttpSession() {
		return httpSession;
	}

	public void setHttpSession(HttpSession httpSession) {
		this.httpSession = httpSession;
	}

	public SessionServer getSessionServer() {
		return sessionServer;
	}

	public void setSessionServer(SessionServer sessionServer) {
		this.sessionServer = sessionServer;
	}

	public Verification getVerification() {
		return verification;
	}

	public void setVerification(Verification verification) {
		this.verification = verification;
	}

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
		this.requestURL = request.getRequestURL().toString();
		this.sessionServer = new SessionServerLocal(request.getSession(),this.verification);
		
	}
	
	protected String success(String target) {
		this.target = target;
		return SUCCESS;
	}

	protected String success() {
		this.target = "";
		return SUCCESS;
	}
	
	/**
	 * 获取当前用户名
	 * @return
	 */
	protected String getCurrentUserName(){
		return this.sessionServer.getUserNameFromSession();
	}
	
	/**
	 * 获取当前请求的url
	 * @return
	 */
	protected String getRequestURL(){
		return this.requestURL;
	}
	

}
